package com.dji.compose_learning.ui.view

import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.imageResource
import androidx.compose.ui.unit.dp
import com.dji.compose_learning.R

data class Message(
    val title: String,
    val body: String
)

@Composable
fun ItemView(msg: Message) {
    var showDetail by remember {
        mutableStateOf(false)
    }

    val surfaceColor: Color by
    animateColorAsState(
        targetValue =
        if (showDetail) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.surface
    )

    Row(modifier = Modifier.padding(10.dp)) {
        Image(
            bitmap = ImageBitmap.imageResource(id = R.drawable.img),
            contentScale = ContentScale.FillWidth,
            contentDescription = "",
            modifier = Modifier
                .size(40.dp)
                .clip(CircleShape),
        )
        Spacer(modifier = Modifier.width(10.dp))
        Column(modifier =
        Modifier
            .background(MaterialTheme.colorScheme.background)
            .clickable {
                showDetail = !showDetail
            }) {
            Text(
                text = "${msg.title}",
                style = MaterialTheme.typography.titleMedium
            )
            Surface(
                color = surfaceColor,
                shape = RoundedCornerShape(5.dp),
                shadowElevation = 1.dp,
                modifier = Modifier
                    .animateContentSize()
                    .padding(1.dp)
            ) {
                Text(
                    text = "${msg.body}",
                    style = MaterialTheme.typography.bodyMedium,
                    modifier = Modifier.padding(4.dp),
                    maxLines = if (showDetail) Int.MAX_VALUE else 1
                )
            }
        }
    }
}
















